//
//  RMMUpOrderYouHuiDetailTableViewCell.m
//  Romomo
//
//  Created by puman on 2017/3/13.
//  Copyright © 2017年 mazegong. All rights reserved.
//

#import "RMMUpOrderYouHuiDetailTableViewCell.h"

@implementation RMMUpOrderYouHuiDetailTableViewCell
{
    UILabel *_youHuiLabel;
    UILabel *_yanZhiLabel;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        NSArray *nameArray = @[@"优惠券抵扣:",@"颜值积分抵扣:"];
        for (int i = 0; i < 2; i++) {
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 15 + kMaric * i, 2 * kHalf, kMaric)];
            label.text = nameArray[i];
            label.textColor = COLORFROMCODE(0x9B9B9B, 1);
            label.font = kFont(14);
            [self.contentView addSubview:label];
            
            UILabel *priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(label.right, label.top, kScreenWideth - label.right - 15, kMaric)];
            priceLabel.textColor = COLORFROMCODE(0xF95B45 , 1);
            priceLabel.font = kFont(14);
            priceLabel.text = @"- ¥0";
            priceLabel.textAlignment = NSTextAlignmentRight;
            [self.contentView addSubview:priceLabel];
            if (i == 0) {
                _youHuiLabel = priceLabel;
            } else {
                _yanZhiLabel = priceLabel;
            }
        }
    }
    return self;
}
- (void)setDic:(NSDictionary *)dic{
    NSString *is_face = [dic objectForKey:@"是否使用颜值"];
    if ([is_face isEqualToString:@"1"]) {
        _yanZhiLabel.text = [NSString stringWithFormat:@"- ¥%@",[dic objectForKey:@"颜值"]];
    }
    NSString *is_youHui = [dic objectForKey:@"是否使用优惠券"];
    if ([is_youHui isEqualToString:@"1"]) {
        NSDictionary *dics = [dic objectForKey:@"优惠券信息"];
        NSString *type = [NSString stringWithFormat:@"%@",dics[@"CARD_TYPE"]];
        if ([type isEqualToString:@"4"]) {
            // 折扣
            NSString *zekou = dics[@"DISCOUNT_RATE"];
            if (zekou.length > 4) {
                _youHuiLabel.text = [NSString stringWithFormat:@"%.2f折",[zekou floatValue] * 10];
            } else {
                _youHuiLabel.text = [NSString stringWithFormat:@"%.1f折",[zekou floatValue] * 10];
            }
        } else if ([type isEqualToString:@"6"]) {
            // 代金券
            _youHuiLabel.text = [NSString stringWithFormat:@"- ¥%@",dics[@"PAR_AMT"]];
        }
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
